#![allow(dead_code)] // 压制为使用警告
use std::io;

fn main() {
    let guess: u32 = "42".parse().expect("Not a number!");
    println!("guess is : {}", guess);

    let _x = 2.0; // f64

    let _y: f32 = 3.0; // f32


    // addition
    let _sum = 5 + 10;

    // subtraction
    let _difference = 95.5 - 4.3;

    // multiplication
    let _product = 4 * 30;

    // division
    let _quotient = 56.7 / 32.2;
    let _floored = 2 / 3; // Results in 0

    // remainder
    let _remainder = 43 % 5;



    let _t = true;

    let _f: bool = false; // with explicit type annotation


    // 元组
    let tup: (i32, f64, u8) = (500, 6.4, 1);
    // 解构
    let (x, y, z) = tup;
    println!("x is {}, y is {}, z is {}", x, y, z);

    let x: (i32, f64, u8) = (500, 6.4, 1);

    let five_hundred = x.0;

    let six_point_four = x.1;

    let one = x.2;
    println!("five_hundred is {}, six_point_four is {}, one is {}", five_hundred, six_point_four, one);


    // 数组
    let _a = [1, 2, 3, 4, 5];
    let _months = ["January", "February", "March", "April", "May", "June", "July",
              "August", "September", "October", "November", "December"];
    let _a: [i32; 5] = [1, 2, 3, 4, 5];
    let _a = [3; 5]; // 等价于 let a = [3, 3, 3, 3, 3];

    let a = [1, 2, 3, 4, 5];

    let first = a[0];
    let second = a[1];
    println!("first is {}, second is {}", first, second);

    let a = [1, 2, 3, 4, 5];

    println!("Please enter an array index.");

    let mut index = String::new();

    io::stdin()
        .read_line(&mut index)
        .expect("Failed to read line");

    let index: usize = index
        .trim()
        .parse()
        .expect("Index entered was not a number");

    let element = a[index];

    println!(
        "The value of the element at index {} is: {}",
        index, element
    );
}
